<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
require_once 'Base/BaseDoctors.class.php';

Class Doctors {

	public function  __construct() {
			if( true == isset( $_SERVER['connection'] ) ) {
				$this->connection = $_SERVER['connection'];
			}
	}

	
	/*******************************************************************************************
	******************************** Fetch Functions *******************************************
	*******************************************************************************************/

	public function fetchSql( $strSql ) {
		$result = $this->connection->RunQuery( $strSql );
		$arrobjDoctors = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objDoctors = new BaseDoctors();
			$objDoctors->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objDoctors->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objDoctors->setSpecilizationId( ( true == isset( $row["specilization_id"] ) ) ? $row["specilization_id"] : 'NULL' );
			$objDoctors->setFirstName( ( true == isset( $row["first_name"] ) ) ? $row["first_name"] : 'NULL' );
			$objDoctors->setMiddleName( ( true == isset( $row["middle_name"] ) ) ? $row["middle_name"] : 'NULL' );
			$objDoctors->setLastName( ( true == isset( $row["last_name"] ) ) ? $row["last_name"] : 'NULL' );
			$objDoctors->setMobileNumber( ( true == isset( $row["mobile_number"] ) ) ? $row["mobile_number"] : 'NULL' );
			$objDoctors->setPhoneNumber( ( true == isset( $row["phone_number"] ) ) ? $row["phone_number"] : 'NULL' );
			$objDoctors->setOfficeNumber( ( true == isset( $row["office_number"] ) ) ? $row["office_number"] : 'NULL' );
			$objDoctors->setSpecilizationDetails( ( true == isset( $row["specilization_details"] ) ) ? $row["specilization_details"] : 'NULL' );
			$objDoctors->setListOfDgress( ( true == isset( $row["list_of_dgress"] ) ) ? $row["list_of_dgress"] : 'NULL' );
			$objDoctors->setIsVisitor( ( true == isset( $row["is_visitor"] ) ) ? $row["is_visitor"] : 'NULL' );
			$objDoctors->setVisitHospitalName( ( true == isset( $row["visit_hospital_name"] ) ) ? $row["visit_hospital_name"] : 'NULL' );
			$objDoctors->setVisitDayName( ( true == isset( $row["visit_day_name"] ) ) ? $row["visit_day_name"] : 'NULL' );
			$objDoctors->setVisitingCharges( ( true == isset( $row["visiting_charges"] ) ) ? $row["visiting_charges"] : 'NULL' );
			$objDoctors->setWardId( ( true == isset( $row["ward_id"] ) ) ? $row["ward_id"] : 'NULL' );
			$objDoctors->setOfficeDetails( ( true == isset( $row["office_details"] ) ) ? $row["office_details"] : 'NULL' );
			$objDoctors->setRoomNumber( ( true == isset( $row["room_number"] ) ) ? $row["room_number"] : 'NULL' );
			$objDoctors->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objDoctors->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objDoctors->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objDoctors->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjDoctors, $objDoctors );
		}
		return $arrobjDoctors;
	}
	public function fetchAllDoctors() {
		$result = $this->connection->RunQuery("SELECT * FROM DOCTORS");
		$arrobjDoctors = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objDoctors = new BaseDoctors();
			$objDoctors->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objDoctors->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objDoctors->setSpecilizationId( ( true == isset( $row["specilization_id"] ) ) ? $row["specilization_id"] : 'NULL' );
			$objDoctors->setFirstName( ( true == isset( $row["first_name"] ) ) ? $row["first_name"] : 'NULL' );
			$objDoctors->setMiddleName( ( true == isset( $row["middle_name"] ) ) ? $row["middle_name"] : 'NULL' );
			$objDoctors->setLastName( ( true == isset( $row["last_name"] ) ) ? $row["last_name"] : 'NULL' );
			$objDoctors->setMobileNumber( ( true == isset( $row["mobile_number"] ) ) ? $row["mobile_number"] : 'NULL' );
			$objDoctors->setPhoneNumber( ( true == isset( $row["phone_number"] ) ) ? $row["phone_number"] : 'NULL' );
			$objDoctors->setOfficeNumber( ( true == isset( $row["office_number"] ) ) ? $row["office_number"] : 'NULL' );
			$objDoctors->setSpecilizationDetails( ( true == isset( $row["specilization_details"] ) ) ? $row["specilization_details"] : 'NULL' );
			$objDoctors->setListOfDgress( ( true == isset( $row["list_of_dgress"] ) ) ? $row["list_of_dgress"] : 'NULL' );
			$objDoctors->setIsVisitor( ( true == isset( $row["is_visitor"] ) ) ? $row["is_visitor"] : 'NULL' );
			$objDoctors->setVisitHospitalName( ( true == isset( $row["visit_hospital_name"] ) ) ? $row["visit_hospital_name"] : 'NULL' );
			$objDoctors->setVisitDayName( ( true == isset( $row["visit_day_name"] ) ) ? $row["visit_day_name"] : 'NULL' );
			$objDoctors->setVisitingCharges( ( true == isset( $row["visiting_charges"] ) ) ? $row["visiting_charges"] : 'NULL' );
			$objDoctors->setWardId( ( true == isset( $row["ward_id"] ) ) ? $row["ward_id"] : 'NULL' );
			$objDoctors->setOfficeDetails( ( true == isset( $row["office_details"] ) ) ? $row["office_details"] : 'NULL' );
			$objDoctors->setRoomNumber( ( true == isset( $row["room_number"] ) ) ? $row["room_number"] : 'NULL' );
			$objDoctors->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objDoctors->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objDoctors->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objDoctors->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjDoctors, $objDoctors);
		}
		return $arrobjDoctors;
	}
	public function fetchAllDoctorsByIds( $arrintIds ) {
		$result = $this->connection->RunQuery("SELECT * FROM DOCTORS WHERE id IN ( implode( "," $arrintIds ) " );
		$arrobjDoctors = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objDoctors->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objDoctors->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objDoctors->setSpecilizationId( ( true == isset( $row["specilization_id"] ) ) ? $row["specilization_id"] : 'NULL' );
			$objDoctors->setFirstName( ( true == isset( $row["first_name"] ) ) ? $row["first_name"] : 'NULL' );
			$objDoctors->setMiddleName( ( true == isset( $row["middle_name"] ) ) ? $row["middle_name"] : 'NULL' );
			$objDoctors->setLastName( ( true == isset( $row["last_name"] ) ) ? $row["last_name"] : 'NULL' );
			$objDoctors->setMobileNumber( ( true == isset( $row["mobile_number"] ) ) ? $row["mobile_number"] : 'NULL' );
			$objDoctors->setPhoneNumber( ( true == isset( $row["phone_number"] ) ) ? $row["phone_number"] : 'NULL' );
			$objDoctors->setOfficeNumber( ( true == isset( $row["office_number"] ) ) ? $row["office_number"] : 'NULL' );
			$objDoctors->setSpecilizationDetails( ( true == isset( $row["specilization_details"] ) ) ? $row["specilization_details"] : 'NULL' );
			$objDoctors->setListOfDgress( ( true == isset( $row["list_of_dgress"] ) ) ? $row["list_of_dgress"] : 'NULL' );
			$objDoctors->setIsVisitor( ( true == isset( $row["is_visitor"] ) ) ? $row["is_visitor"] : 'NULL' );
			$objDoctors->setVisitHospitalName( ( true == isset( $row["visit_hospital_name"] ) ) ? $row["visit_hospital_name"] : 'NULL' );
			$objDoctors->setVisitDayName( ( true == isset( $row["visit_day_name"] ) ) ? $row["visit_day_name"] : 'NULL' );
			$objDoctors->setVisitingCharges( ( true == isset( $row["visiting_charges"] ) ) ? $row["visiting_charges"] : 'NULL' );
			$objDoctors->setWardId( ( true == isset( $row["ward_id"] ) ) ? $row["ward_id"] : 'NULL' );
			$objDoctors->setOfficeDetails( ( true == isset( $row["office_details"] ) ) ? $row["office_details"] : 'NULL' );
			$objDoctors->setRoomNumber( ( true == isset( $row["room_number"] ) ) ? $row["room_number"] : 'NULL' );
			$objDoctors->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objDoctors->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objDoctors->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objDoctors->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjDoctors, $objDoctors );
		}
		return $arrobjDoctors;
	}

	public function fetchDoctorsById( $intId ) {
		$result = $this->connection->RunQuery( "SELECT * FROM DOCTORS WHERE id = " . $intId );
			$objDoctors = NULL;
		while($row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objDoctors = new BaseDoctors();
			$objDoctors->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objDoctors->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objDoctors->setSpecilizationId( ( true == isset( $row["specilization_id"] ) ) ? $row["specilization_id"] : 'NULL' );
			$objDoctors->setFirstName( ( true == isset( $row["first_name"] ) ) ? $row["first_name"] : 'NULL' );
			$objDoctors->setMiddleName( ( true == isset( $row["middle_name"] ) ) ? $row["middle_name"] : 'NULL' );
			$objDoctors->setLastName( ( true == isset( $row["last_name"] ) ) ? $row["last_name"] : 'NULL' );
			$objDoctors->setMobileNumber( ( true == isset( $row["mobile_number"] ) ) ? $row["mobile_number"] : 'NULL' );
			$objDoctors->setPhoneNumber( ( true == isset( $row["phone_number"] ) ) ? $row["phone_number"] : 'NULL' );
			$objDoctors->setOfficeNumber( ( true == isset( $row["office_number"] ) ) ? $row["office_number"] : 'NULL' );
			$objDoctors->setSpecilizationDetails( ( true == isset( $row["specilization_details"] ) ) ? $row["specilization_details"] : 'NULL' );
			$objDoctors->setListOfDgress( ( true == isset( $row["list_of_dgress"] ) ) ? $row["list_of_dgress"] : 'NULL' );
			$objDoctors->setIsVisitor( ( true == isset( $row["is_visitor"] ) ) ? $row["is_visitor"] : 'NULL' );
			$objDoctors->setVisitHospitalName( ( true == isset( $row["visit_hospital_name"] ) ) ? $row["visit_hospital_name"] : 'NULL' );
			$objDoctors->setVisitDayName( ( true == isset( $row["visit_day_name"] ) ) ? $row["visit_day_name"] : 'NULL' );
			$objDoctors->setVisitingCharges( ( true == isset( $row["visiting_charges"] ) ) ? $row["visiting_charges"] : 'NULL' );
			$objDoctors->setWardId( ( true == isset( $row["ward_id"] ) ) ? $row["ward_id"] : 'NULL' );
			$objDoctors->setOfficeDetails( ( true == isset( $row["office_details"] ) ) ? $row["office_details"] : 'NULL' );
			$objDoctors->setRoomNumber( ( true == isset( $row["room_number"] ) ) ? $row["room_number"] : 'NULL' );
			$objDoctors->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objDoctors->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objDoctors->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objDoctors->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
		}
		return $objDoctors;
	}

	public function GetKeysOrderBy($column, $order){
		$keys = array(); $i = 0;
		$result = $this->connection->RunQuery("SELECT id from doctors order by $column $order");
			while($row = $result->fetch_array(MYSQLI_ASSOC)){
				$keys[$i] = $row["id"];
				$i++;
			}
	return $keys;
	}

	public function endDoctors(){
		$this->connection->CloseMysql();
	}

}